﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Warehouse.UI.WinForm.Controls
{
    public partial class PanelOkCancel : UserControl
    {
        //public delegate void MyEventHandler(object sender, EventArgs e);
        public event System.EventHandler btnOkClick = null;
        public event System.EventHandler btnCancelClick = null;

        public PanelOkCancel()
        {
            InitializeComponent();
            this.btnOk.Text = "确定(&O)";
            this.btnCancel.Text = "取消(&C)";
        }

        public int RunState
        {
            set
            {
                if (value == 1)
                    this.Cursor = Cursors.WaitCursor;
                btnOk.Enabled = (value == 0);
                btnCancel.Enabled = (value == 0);
                if (value == 0)
                    this.Cursor = Cursors.Default;
            }
        }

        private void pnlOkCancel_Load(object sender, EventArgs e)
        {
            //
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.RunState = 1;
            try
            {
                if (btnOkClick != null) btnOkClick(btnOk, e);
            }
            finally
            {
                this.RunState = 0;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.RunState = 1;
            try
            {
                if (btnCancelClick != null) btnCancelClick(btnCancel, e);
            }
            finally
            {
                this.RunState = 0;
            }
        }
    }
}
